#!/usr/bin/python
import memcache
from config import *
def loadHtmlFile(file):
    f = open(file,'r')
    return f.read()

def render():
    html = loadHtmlFile('%sindex.html' % (htmlPath))
    return html

class MC:
    def __init__(self,ip):
        self.conn(ip);
    def conn(self,ip):
        self.mc = memcache.Client([ip], debug=0)
        return self.mc
    def set(self,key,value):
        key = key.encode('UTF-8')
        value = value.encode('UTF-8')
        self.mc.set(key,value)
    def delete(self,key):
        self.mc.delete(key)
    def get(self,key):
        key = key.encode('UTF-8')
        return self.mc.get(key)

def chkuser(user,mc):
    key = mc.get(user)
    if(key == None):
        return 1
    else:
        return 0
def chklogin(web,mc):
    talk = web.cookies()
    try:
        user = talk.user
        passwd = talk.passwd
    except:
        return None
    if(chkuser(user,mc) or mc.get(user) != passwd):
        return None
    return user
